package com.shenzw.mybatisdemo.controller;

import com.shenzw.mybatisdemo.domain.User;
import com.shenzw.mybatisdemo.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author shenzw
 * @date 2023/8/30
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@Slf4j
public class UserController {

    private final UserService userService;

    @GetMapping("/getUser/{id}")
    public User getUser(@PathVariable int id) {
        return userService.getUser(id);
    }

    @PostMapping("/insertUser")
    public Integer insertUser(@RequestBody User user) {
        return userService.insertUser(user);
    }

    @PostMapping("/batchInsertUser")
    public void batchInsertUser() {
        long start = System.currentTimeMillis();
        userService.batchInsertUser();
        log.info("batchInsertUser consumer millis = {}", System.currentTimeMillis() - start);
    }

}
